import { Map } from 'immutable'

import { SWITCHCHECK } from './actionTypes'

import store from 'store'

let checked = store.get('checked')

const defaultState = Map({
  // checked: JSON.parse(localStorage.getItem('checked') || true)
  checked: checked === undefined ? true : checked
})

const reducer = (state=defaultState, action) => {
  switch(action.type) {
    case SWITCHCHECK:
      localStorage.setItem('checked', action.checked)
      store.set('checked', action.checked)
      return state.set('checked', action.checked)

    default:
      return state
  }
}

export default reducer